package abc.exception;

import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatusCode;
import org.springframework.web.server.ResponseStatusException;

/**
 * 参数异常类
 * @author Administrator
 *
 */
public class ParamException extends ResponseStatusException {
    /**
     *
     */
    private static final long serialVersionUID = -5962296753554846774L;

    /**
     * 错误状态码
     */
    private int errorCode = 500;

    public ParamException() {
        super(HttpStatus.BAD_REQUEST, "Invalid parameter!!!");
        setErrorCode(HttpStatus.BAD_REQUEST.value());
    }
    /**
     * 错误消息
     * @param msg
     */
    public ParamException(String msg) {
        super(HttpStatus.BAD_REQUEST, msg);
        setErrorCode(HttpStatus.BAD_REQUEST.value());
    }
    public ParamException(int errorCode, String msg){
        super(HttpStatus.valueOf(errorCode), msg);
        this.errorCode = errorCode;
    }
    public int getErrorCode() {
        return errorCode;
    }
    public void setErrorCode(int errorCode) {
        this.errorCode = errorCode;
    }

    @Override
    public String getMessage() {
        return (this.getReason() != null ? this.getReason() : "");
    }
}
